#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Graphics3D;
using Graphics;
#endregion

namespace NI_Annimation_XNA
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        XNARenderer renderer;
        // make sure player doesn't change textures too fast
        private const double TEXTURE_DELAY = 0.25;
        private double m_timeSinceLastSelectNextEffect = TEXTURE_DELAY;
        private Graphics3D.XNASceneController sceneController;
        // the standard constructor
        public Game1()
        {
            //renderer = new XNARenderer(this);
            sceneController = new Graphics3D.XNASceneController(this);
            // run at full speed
            IsFixedTimeStep = false;
        }

        /// Load your graphics content.
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            sceneController.LoadGraphicsContent(loadAllContent);
        }

        /// game logic such as updating the world
        protected override void Update(GameTime gameTime)
        {
            //this.renderer.Update(gameTime);
            //base.Update(gameTime);
            // TODO: Add your update code here
            // Allows the default game to exit on Xbox 360 and Windows
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // time in seconds since last call to update
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //// rotate the teapot mesh
            //m_meshTeapot.Rotate(17.0f * elapsed, 9.0f * elapsed, 7.5f * elapsed);

            //// rotate the balls
            //foreach (MyMesh ball in m_meshBall)
            //{
            //    ball.Rotate(0, 23.0f * elapsed, 0);
            //}

            // process player input, add delay between texture changes
            //m_timeSinceLastSelectNextEffect += elapsed;
            ProcessInput(GamePad.GetState(PlayerIndex.One), Keyboard.GetState(), elapsed);
            base.Update(gameTime);
        }

        // process input from keyboard and gamepad
        public void ProcessInput(GamePadState pad1, KeyboardState key1, float elapsed)
        {
            // change teapot texture?
            if (pad1.Buttons.A == ButtonState.Pressed || key1.IsKeyDown(Keys.Space))
            {
                //sceneController.SelectNextEffect();
            }

            (sceneController.Camera as XNACamera).ProcessInput(pad1, key1, elapsed);
        }

        /// render game objects
        protected override void Draw(GameTime gameTime)
        {
            sceneController.Render();
            base.Draw(gameTime);
        }


    }
}
